<?php
/* 
$Id: xsell_products.php, v1  2002/09/11

osCommerce, Open Source E-Commerce Solutions 
<http://www.oscommerce.com> 

Copyright (c) 2002 osCommerce 

Released under the GNU General Public License 
*/ 
class osC_Content_cross_sell extends osC_Modules {
    var $_title,
        $_code = 'cross_sell',
        $_author_name = 'osCommerce',
        $_author_www = 'http://www.oscommerce.com',
        $_group = 'content';

/* Class constructor */
function osC_Content_cross_sell() {
      global $osC_Language;

      $this->_title = $osC_Language->get('cross_sell_title');
	 
	  }
function initialize() {
      global $osC_Database, $osC_Image, $osC_Language, $osC_Template;
	
	$pid=array();
	  foreach($_GET as $key=>$value)
	{
		  $pid[]=$key;
	}
            $productid=$pid[0];

            $productsid_query = $osC_Database->query('SELECT products_id from :table_products_description WHERE products_keyword = :products_keyword');
            $productsid_query->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
            $productsid_query->bindValue(':products_keyword', $productid);
            $productsid_query->execute();
            
            while ($proid=$productsid_query->next()) {
                $products_id= $proid['products_id'];
                }
 


            $cross_sell_query = $osC_Database->query('select distinct p.products_status, xp.xsell_id, xp.products_id, pd.products_name, pd.products_keyword, pip.image FROM :table_products p, :table_products_xsell xp left join :table_products_images pip on (xp.xsell_id = pip.products_id and pip.default_flag = 1), :table_products_description pd WHERE xp.products_id = :products_id AND pd.products_id = xp.xsell_id and xp.xsell_id = p.products_id and p.products_status = 1');
            $cross_sell_query->bindTable(':table_products_xsell', TABLE_PRODUCTS_XSELL);
            $cross_sell_query->bindTable(':table_products', TABLE_PRODUCTS);
            $cross_sell_query->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION);
            $cross_sell_query->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES);
            $cross_sell_query->bindInt(':products_id', $products_id);
            $cross_sell_query->execute();

                if ($cross_sell_query->numberOfRows() > 0){

                    $i = 0;
   
                        while ($product=$cross_sell_query->next()) {
                            
                            if (($i % 3 == 0) && ($i != 0))
                                
                                $this->_content .= '<div style="clear:both"></div>';
                                    $products = new osC_Product($cross_sell_query->valueInt('xsell_id'));
                                $this->_content .= '<div style="float:left; width: 33%; text-align: center">' . osc_link_object(osc_href_link(FILENAME_PRODUCTS, $product['products_keyword']), $osC_Image->show($product['image'], $product['products_name'])) .
                                                   '<span style="display:block; height: auto; text-align: center">' . osc_link_object(osc_href_link(FILENAME_PRODUCTS, $product['products_keyword']), $product['products_name']) . '</span>' .
                                                   '<span style="display:block; padding: auto; text-align: center">' . $products->getPriceFormated(true) . '</span><br /></div>';

                        $i ++;

                    }
            $this->_content .= '<div style="clear:both"></div>';
        }
      $cross_sell_query->freeResult();
    }
}
?>